import {
  voteListParamsType,
  pageType,
  publishVoteParamsType,
  voteListResponseType,
  editVoteParamsType,
} from "@/types/vote";

import type { MyVoteResponse, myEntereType } from "@/types/vote";

import { http } from "@/utils/request";

// 发布投票
export const postPublishVoteAPI = (data: publishVoteParamsType) => {
  return http<string>({
    method: "POST",
    url: "/api/v1/activity/publish",
    data,
  });
};

// 获取投票展示列表
export const getVoteListAPI = (data: voteListParamsType) => {
  return http<pageType<voteListResponseType>>({
    method: "POST",
    url: "/api/v1/activity/list",
    data,
  });
};

//删除投票活动
export const deleteVoteAPI = (activityId: string) => {
  return http<string>({
    method: "GET",
    url: "/api/v1/activity/delete/activity", //删除选手信息
    header: {
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
    data: {
      id: activityId,
    },
  });
};

//获取我的投票活动列表
export const getMyVoteListAPI = (state: string) => {
  return http<voteListResponseType[]>({
    method: "POST",
    url: "/api/v1/activity/mylist",
    data: {
      state,
    },
  });
};

//修改投票活动信息
export const putVoteAPI = (data: editVoteParamsType) => {
  return http<string>({
    method: "PUT",
    url: "/api/v1/activity/modify/activity",
    data,
  });
};

// 获取我的投票记录
export const getMyVoteAPI = () => {
  return http<MyVoteResponse>({
    method: "GET",
    url: "/api/v1/activity/myvote",
  });
};

// 获取我报名过的活动
export const getMyEnteredAPI = () => {
  return http<myEntereType[]>({
    method: "GET",
    url: "/api/v1/activity/myenter",  
  });
};

//获取投票详情
export const getVoteDetailAPI = (actId: string) => {
  return http<voteListResponseType>({
    method: "GET",
    url: "/api/v1/activity/detail",
    header: {
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
    data: {
      actId,
    },
  });
};
